package cn.wolfcode.shop.util;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * Created by wolfcode-lanxw
 */
public class MD5Util {
    public static String salt = "1a2d3c4d";
    /**
     * md5加密
     * @param src
     * @return
     */
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    /**
     * 用户输入明文变成密文
     * @param pass
     * @param salt
     * @return
     */
    public static String inputPassToFormPass(String pass,String salt){
        String str = ""+salt.charAt(0)+salt.charAt(2)+pass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }

    /**
     * 程序端密文在进行随机盐的加密
     * @param pass
     * @param salt
     * @return
     */
    public static String formPassToDbPass(String pass,String salt){
        String str = ""+salt.charAt(0)+salt.charAt(2)+pass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }
    public static void main(String[] args) {
        String inputPass = inputPassToFormPass("111111", salt);
        String dbPass = formPassToDbPass(inputPass,"1a2d3c4d");
    }
}
